package com.qf.utils;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;

import javax.xml.ws.http.HTTPException;
import java.io.IOException;

/**
 * @author: lch
 * @Date:2023/4/7
 */
public class MessageSendingUtils {
    /**
     * 腾讯云短信
     * 方法说明
     * @param phone
     * @return void
     * @Discription:扩展说明
     * @throws HTTPException  http status exception
     * @throws IOException    network problem
     */
    public static void sendMsg(String phone,String code) throws Exception {

        // 短信应用SDK AppID
        // 1400开头
        int appId = 1400810001;

        // 短信应用SDK AppKey
        String appKey = "77422060218f6578f1ed2ead40244cca";

        // 需要发送短信的手机号码
        String[] phoneNumbers = {"13682605500"};

        // 短信模板ID，需要在短信应用中申请
        int templateId = 1757799;

        // 签名
        String smsSign = "VDLYSecre公众号";

        // 短信模板内容
        // 和腾讯云选择的模板参数要对应
        String[] params = {code,"5"};

        SmsSingleSender sSender = new SmsSingleSender(appId, appKey);
        //第一个参数0表示普通短信,1表示营销短信
        SmsSingleSenderResult result = sSender.sendWithParam("86",
                phoneNumbers[0],
                templateId,
                params,
                smsSign,
                "",
                "");

        System.out.println(result);

        if (result.result != 0) {
            throw new Exception("send phone validateCode is error" + result.errMsg);
        }
    }

}
